/**
 * 帖子相关功能JS文件
 * 
 * @author		布衣才子
 * @date		2012-10-01
 * @email		work.jerryliu@gmail.com
 * @qq			394969553
 * @version		v1.0
 * @copyright	copyright 2012-2014	YeeYi.com All Rights Reserved	
 */


/**
 * 服务器访问地址
 */
var forumHost = "http://www.yeeyi.com/bbs/forum.php?jsoncallback=?&mod=mobile";

/**
 * 用于分页
 */
var forumPage = 1;

/**
 * 用于回复分页
 */
var postPage = 1;

/**
 * 用于多个confirm的识别
 */
var confirmTag = 0;

/**
 * 用于多个sheet的识别
 */
var sheetTag = 1;	

/**
 * base64 加密对象初始化
 */
var b64 = new Base64();

/**
 * 网络访问函数
 * @param {Object} url	请求的网络地址
 * @param {Object} callback	回调函数
 */
function xmlHttp(url,callback){
	if(url == ''){
		uexWindow.alert('参数错误','请求地址不能为空！','返回');
	}else{
		var platform = getLocalStorge('platform');
		url = url + "&pf="+platform;
		$.getJSON(url,callback);
	}
}


/**
 * 获取板块名称
 * @param {Object} fid
 */
function getForumName(fid){
	var furl = forumHost + '&ac=forumname&fid='+fid;
	xmlHttp(furl,showForumName);
}

/**
 * 获取板块名称的回调函数，显示板块名称
 * @param {Object} data
 */
function showForumName(data){
	var returnCode = data.code;
	if(returnCode == '200'){
		uexWindow.evaluateScript("forum_list","1","changeHead('"+b64.decode(data.fname)+"')");
	}
}

/**
 * 回去对应板块的帖子列表
 * @param {Object} fid	板块ID
 */
function  getForumList(fid){
	uexWindow.toast("1","5","数据加载中…","0");
	localStorage.setItem("fid",fid);
	
	forumPage = 1;
	var url = forumHost + '&ac=list&fid='+fid;
	xmlHttp(url,showList);
}

/**
 * 显示帖子列表
 * @param {Object} items
 */
function showList(items){
	var outNewsObj = $("#forum_list");
	outNewsObj.html('');
	
	for(var i in items){
		var item = items[i];
		var hasImg = '';
		var parm = '';
		if(item.attachment == 'yes'){
			hasImg = ' <img src="css/images/attachimg.png">';		
		}
		
		if(item.replies >= 50){
			parm = " <img src='css/images/recommend.gif'>";
		}else if(item.views >= 2000){
			parm = " <img src='css/images/hot_3.gif'>";
		}else if(item.views >= 1200){
			parm = " <img src='css/images/hot_2.gif'>";
		}else if(item.views >= 700){
			parm = " <img src='css/images/hot_1.gif'>";
		}
		
		var tr = '';
		var trHeader = '<div ontouchstart="zy_touch(\'btn-newact\')" class="forumList" onclick="goThreadWindow('+item.tid+')"><div class="ub-f1 ub ub-ver">';
		var trTitle = '<div class="title">'+b64.decode(item.subject)+hasImg+parm+'</div>';
		var trOtherInfo = '<div class="otherInfo"><span>'+b64.decode(item.dateline)+' '+b64.decode(item.author)+' 回复'+item.replies+'/查看'+item.views+'</span></div>';
		var trDesc = '<div class="desc">'+b64.decode(item.message)+'</div>';
		var trFooter = '</div></div>';
		tr = trHeader+trTitle+trOtherInfo+trDesc+trFooter;
		outNewsObj.append(tr);
	}
	uexWindow.closeToast();
}

/**
 * 显示下一页帖子列表
 * @param {Object} items
 */
function showMoreThread(items){
	var outThreadObj = $("#forum_list");
	
	for(var i in items){
		var item = items[i];
		var hasImg = '';
		var parm = '';
		if(item.attachment == 'yes'){
			hasImg = ' <img src="css/images/attachimg.png">';			
		}
		
		if(item.replies >= 50){
			parm = " <img src='css/images/recommend.png'>";
		}else if(item.views >= 2000){
			parm = " <img src='css/images/hot_3.gif'>";
		}else if(item.views >= 1200){
			parm = " <img src='css/images/hot_2.gif'>";
		}else if(item.views >= 700){
			parm = " <img src='css/images/hot_1.gif'>";
		}
		
		
		var tr = '';
		var trHeader = '<div ontouchstart="zy_touch(\'btn-newact\')" class="forumList" onclick="goThreadWindow('+item.tid+')"><div class="ub-f1 ub ub-ver">';
		var trTitle = '<div class="title">'+b64.decode(item.subject)+hasImg+parm+'</div>';
		var trOtherInfo = '<div class="otherInfo"><span>'+b64.decode(item.dateline)+' '+b64.decode(item.author)+' 回复'+item.replies+'/查看'+item.views+'</span></div>';
		var trDesc = '<div class="desc">'+b64.decode(item.message)+'</div>';
		var trFooter = '</div></div>';
		tr = trHeader+trTitle+trOtherInfo+trDesc+trFooter;
		outThreadObj.append(tr);
	}
	uexWindow.closeToast();
	$("#nextpage").text("查看下10条");
}

/**
 * 获取下一页帖子列表
 */
function getMoreThread(){
	var fid = getLocalStorge('fid');
	if(!fid){
		uexWindow.toast("0","5","板块ID丢失，请重新操作…","2000");
		return false;
	}
	forumPage = forumPage + 1;
	var url = forumHost + '&ac=list&fid='+fid+'&page='+forumPage;
	
	$("#nextpage").text("数据加载中……");
	xmlHttp(url,showMoreThread);
}

/**
 * 帖子详情跳转函数
 * @param {Object} tid
 */
function goThreadWindow(tid){
	if(tid == ''){
		uexWindow.alert("ERROR","未指定帖子ID,无法加载帖子内容！","返回");
	}else{
		localStorage.setItem("tid",tid);
		var threadUrl = "viewthread.html";
		uexWindow.open("threadWindow",0,threadUrl,2,"","",0x0);
	}
}

/**
 * 获取帖子详情
 */
function showThread(){
	uexWindow.toast("1","5","数据加载中…","0");
	var tid = localStorage.getItem("tid");
	
	if(tid == ''){
		uexWindow.alert("ERROR","未指定帖子ID,无法加载帖子内容！","返回");
		uexWindow.close(-1);
	}else{
		var url = forumHost + '&ac=viewthread&tid='+tid;
		xmlHttp(url,parseThread);
	}
}

/**
 * 发布新帖后的远程调用函数
 */
function showNewThread(){
	uexWindow.toast("1","5","数据加载中…","0");
	var tid = localStorage.getItem("tid");
	
	if(tid == ''){
		uexWindow.alert("ERROR","未指定帖子ID,无法加载帖子内容！","返回");
		uexWindow.close(-1);
	}else{
		var url = forumHost + '&ac=viewthread&tid='+tid;
		xmlHttp(url,parseNewThread);
	}
}

/**
 * 新帖显示
 * @param {Object} data
 */
function parseNewThread(data){
	var postObj = $("#viewthread");
	var title = b64.decode(data.subject);
	var authorid = data.authorid;
	var replies = data.replies;
	var content = b64.decode(data.message);
	var fid = data.fid;
	localStorage.setItem('fid',fid);
	
	var otherInfo = b64.decode(data.dateline)+' '+b64.decode(data.author)+' 回复'+data.replies+'/查看'+data.views;
	//用于提升帖子
	localStorage.setItem('authorid',data.authorid);
	
	$(".title").html(title);
	$(".otherInfo span").html(otherInfo);
	$(".desc").html(content);
	$(".totalReply span").html("点击回复");
	$(".post").remove();
	$(".footer").hide();
	
	localStorage.setItem('title',title);
	uexWindow.closeToast();
}

/**
 * 帖子回调显示
 * @param {Object} data
 */
function parseThread(data){
	
	postPage = 1;
	var postObj = $("#viewthread");
	var title = b64.decode(data.subject);
	var authorid = data.authorid;
	var replies = data.replies;
	var content = b64.decode(data.message);
	var fid = data.fid;
	localStorage.setItem('fid',fid);
	var comment = data.comm;
	
	var otherInfo = b64.decode(data.dateline)+' '+b64.decode(data.author)+' 回复'+data.replies+'/查看'+data.views;
	var k = 0;
	var commentContent = '<div class="viewthread_commontHead">点 评 </div>';
	for(var k in comment){
		var commentObj = comment[k];
		commentContent = commentContent + '<div class="postcomment"><span style="font-weight: bold;">'+b64.decode(commentObj.author)+': </span><span>'+b64.decode(commentObj.comment)+'</span></div>';
		k = k + 1;
	}
	
	
	//用于提升帖子
	localStorage.setItem('authorid',data.authorid);
	
	$(".title").html(title);
	$(".otherInfo span").html(otherInfo);
	$(".desc").html(content);
	$(".totalReply span").html("点击回复");
	
	if(k > 0){
		$('.viewthread_content').append(commentContent);
	}
	localStorage.setItem('title',title);
	
	var posts = data.post;
	var j = 1;
	var headThumb;
	var louceng;
	var h = 0;
	//显示posts
	for(var i in posts){
		j = j + 1;
		if(j == 2){
			louceng = '沙发';
		}else if(j == 3){
			louceng = '藤椅';
		}else if(j == 4){
			louceng = '板凳';
		}else if(j == 5){
			louceng = '报纸';
		}else if(j == 6){
			louceng = '地板';
		}else{
			louceng = j + '#';
		}
		h = 0;
		var reply = posts[i];
		headThumb = 'http://center.yeeyi.com/avatar.php?uid='+reply.authorid+'&size=small';
		var postDiv = '';
		var postDivHead = '<div ontouchstart="zy_touch(\'btn-newact\')" class="post" onclick="showReply('+reply.pid+');" title="'+reply.pid+'"><div class="post_header">';
		var postDivThumb = '<img src="'+headThumb+'" alt="">';
		var postAuthor = '<span class="post_author" title="'+reply.authorid+'"><span class="authorLeft">'+b64.decode(reply.author)+'</span><span class="louceng">'+louceng+'</span></span>';
		var postDateline = '<div class="comment-meta"><span class="meta-sep">'+b64.decode(reply.dateline)+'</span></div></div>';
		var postcommentObj = reply.comment;
		var postcomment = '<div class="viewthread_commontHead">点 评 </div>';
		for(h in postcommentObj){
			var pcomment = postcommentObj[h];
			postcomment = postcomment + '<div class="postcomment"><span style="font-weight: bold;">'+b64.decode(pcomment.author)+': </span><span>'+b64.decode(pcomment.comment)+'</span></div>';
			h = h + 1;
		}
		if(h == 0){
			postcomment = '';
		}
		var postContent = '<div class="post_content">'+b64.decode(reply.message)+postcomment+'</div>';
		var postFooter = '</div>';
		
		
		
		postDiv = postDivHead + postDivThumb + postAuthor + postDateline + postContent + postFooter;
		postObj.append(postDiv);
	}
	
	if(j == 11){
		$('.footer').show();
	}
	
	uexWindow.closeToast();
}

/**
 * 主贴的操作菜单显示
 * @param {Object} pid
 */
function showReply(pid){
	var groupid = getLocalStorge('groupid');
	var toReplyUsername = $('.post[title="'+pid+'"] .post_author .authorLeft').text();
	var toReplyUid = $('.post[title="'+pid+'"] .post_author').attr('title');

	localStorage.setItem('toReUid',toReplyUid);
	localStorage.setItem('toReUsername',toReplyUsername);
	localStorage.setItem('rpid',pid);
	var uid = getLocalStorge('uid');
	if(!uid){
		var confirmButtom = new Array();
		confirmButtom[0] = '登录';
		confirmButtom[1] = '返回';
		confirmTag = 3;
		uexWindow.confirm('提示：','请登录后再进行操作！',confirmButtom);
		return false;
	}
	
	
	sheetTag = 1;
	
	if(in_array(groupid,['1','2','3','57','62','42'])){
		var menuArr = new Array(3);
		menuArr[0] = '回  复';
		menuArr[1] = '引 用';
		menuArr[2] = '禁 言';	
		menuArr[3] = '删  除';
	}else{
		var menuArr = new Array(2);
		menuArr[0] = '回 复';
		menuArr[1] = '引 用';
	}
	uexWindow.actionSheet('帖子回复操作','取消',menuArr);
}

/**
 * actionSheet 控件监控函数
 * @param {Object} opId
 * @param {Object} dataType
 * @param {Object} data
 */
function actionReplySheet(opId,dataType,data){
	var groupid = getLocalStorge('groupid');
	
	if (sheetTag == 1) {
		//监控回复帖子的操作
		if (in_array(groupid, ['1', '2', '3', '57', '62', '42'])) {
			if (data == 0) {
				localStorage.setItem('quote','');
				uexWindow.open('subreply', '0', 'sub_reply.html', '2', '100%', '100%', 4);
			}else if(data == 1){
				var rpid = getLocalStorge('rpid');
				localStorage.setItem('quote',rpid);
				uexWindow.open('subreply', '0', 'sub_reply.html', '2', '100%', '100%', 4);
			}else if (data == 2) {
					//删除回复确认
					var confirmButtom = new Array();
					confirmButtom[0] = '确定';
					confirmButtom[1] = '取消';
					confirmTag = 2;
					uexWindow.confirm('提示：', '您确定要禁言该用户？', confirmButtom);
			}else if (data == 3) {
					//删除回复确认
					var confirmButtom = new Array();
					confirmButtom[0] = '确定';
					confirmButtom[1] = '取消';
					confirmTag = 1;
					uexWindow.confirm('提示：', '您确定要删除该回复？', confirmButtom);
			}
		}else {
			if (data == 0) {
				localStorage.setItem('quote','');
				uexWindow.open('subreply', '0', 'sub_reply.html', '2', '100%', '100%', 4);
			}else if(data == 1){
				var rpid = getLocalStorge('rpid');
				localStorage.setItem('quote',rpid);
				uexWindow.open('subreply', '0', 'sub_reply.html', '2', '100%', '100%', 4);
			}
		}
		
	}else if(sheetTag == 2){
		//用于监控主题的点击操作
		var uid = getLocalStorge('uid');
		var authorid = getLocalStorge('authorid');
		var tid = getLocalStorge('tid');
		var password = getLocalStorge('pwd');
		var fid = getLocalStorge('fid');
		
		if(authorid == uid){
			var upFids = ['3','316','627','626','625','624','623','622','304','305','635','634','633','325','632','631','630','309','598','604','89','641','642','643'];
			if(in_array(fid,upFids,false)){
				var menulist=new Array(2);
				if (data == 1) {
					//提升自己的帖子
					if(!tid){
						uexWindow.toast("0","5","失败！帖子ID丢失！","2000");
						return false;
					}
					
					uexWindow.toast("1", "5", "正在进行操作……！", "0");
					var requestUrl = forumHost + '&ac=upthread&tid=' + tid + '&pwd=' + password + '&uid=' + uid + '&groupid=' + groupid;
					xmlHttp(requestUrl, showUpResult);
					
				}else if(data == 0){
					//回复自己的帖子
					uexWindow.open('reply', '0', 'reply.html', '2', '100%', '100%', 4);
				}
			}else{
				if(data == 0){
					//回复
					uexWindow.open('reply', '0', 'reply.html', '2', '100%', '100%', 4);
				}
			}
		}else{
			//如果是管理组
			if(in_array(groupid,['1','2','3','57','62','42'])){
				var confirmButtom = new Array();
				confirmButtom[0] = '确定';
				confirmButtom[1] = '取消';
				if(data == 0){
					//回复
					localStorage.setItem('QThread','');
					uexWindow.open('reply', '0', 'reply.html', '2', '100%', '100%', 4);
				}else if(data == 1){
					addToFavorite();
				}else if(data == 2){
					confirmTag = 5;
					uexWindow.confirm('提示：','您确定要禁言该用户？',confirmButtom);
				}
				else if(data == 3){
					confirmTag = 4;
					uexWindow.confirm('提示：','您确定要删除该帖子？',confirmButtom);
				}
			}else{
				if(data == 0){
					//回复
					uexWindow.open('reply', '0', 'reply.html', '2', '100%', '100%', 4);
				}else if(data == 1){
					localStorage.setItem('QThread',tid);
					//引用楼主帖子
					uexWindow.open('reply', '0', 'reply.html', '2', '100%', '100%', 4);
				}else if(data == 2){
					addToFavorite();
				}
			}
		}
	}	
}

/**
 * confirm控件监控函数
 * @param {Object} opId
 * @param {Object} dataType
 * @param {Object} data
 */
function confirmSuccess(opId,dataType,data){
	var pid = getLocalStorge('rpid');
	var uid = getLocalStorge('uid');
	var password = getLocalStorge('pwd');
	var author_id = getLocalStorge('toReUid');
	var tid = getLocalStorge('tid');
	
	if(confirmTag == 1){
		if(data == 0){
			uexWindow.toast("1", "5", "正在进行操作……！", "0");
			var DelURL = forumHost + '&ac=delpost&pid='+pid+'&authorid='+author_id+'&uid='+uid+'&pwd='+password;
			xmlHttp(DelURL,showDelPostResult);
		}
	}else if(confirmTag == 2){
		if (data == 0) {
			uexWindow.toast("1", "5", "正在进行操作……！", "0");
			var banURL = forumHost + '&ac=ban&authorid=' + author_id + '&pwd=' + password + '&uid=' + uid;
			xmlHttp(banURL, BanUser);
		}
	}else if(confirmTag == 3){
		if (data == 0) {
			localStorage.setItem('returnType','viewthread');
			uexWindow.open('login','0','login.html','1','100%','100%','0');
		}
	}else if(confirmTag == 4){
		if (data == 0) {
			uexWindow.toast("1", "5", "正在进行操作……", "0");
			var delURL = forumHost + '&ac=delete&tid=' + tid + '&uid=' + uid + '&pwd=' + password;
			xmlHttp(delURL, deleteThread);
		}
	}else if(confirmTag == 5){
		if (data == 0) {
			uexWindow.toast("1", "5", "正在进行操作……", "0");
			var authorid = getLocalStorge('authorid');
			var banURL = forumHost + '&ac=ban&authorid=' + authorid + '&pwd=' + password + '&uid=' + uid;
			xmlHttp(banURL, banUser);
		}
	}
}


/**
 * 版主或管理员删除帖子的回调函数
 * @param {string} data 
 */
function deleteThread(data){
	uexWindow.closeToast();
	
	var returnCode = data.info;
	if(returnCode == '200'){
		uexWindow.toast("0","5","帖子删除成功,请返回刷新…","2000");
		$('.post').remove();
		$('.title').text("提示： 帖子已被删除，请返回刷新!");
		$('.desc').text("提示： 帖子已被删除，请返回刷新!");
		$('.otherInfo span').text("");
	}else if(returnCode == '401'){
		uexWindow.toast("0","5","操作失败，用户名或密码错误…","2000");
	}else if(returnCode == '402'){
		uexWindow.toast("0","5","操作失败，无权操作管理组帖子…","2000");
	}else if(returnCode == '403'){
		uexWindow.toast("0","5","操作失败，您没有该权限…","2000");
	}else if(returnCode == '404'){
		uexWindow.toast("0","5","操作失败，帖子ID丢失…","2000");
	}else{
		uexWindow.toast("0","5","操作失败，未知错误…","2000");
	}
}


/**
 * 版主或管理员禁言用户的回调函数
 * @param {string} data 
 */
function banUser(data){
	uexWindow.closeToast();
	var returnCode = data.info;
	if(returnCode == '200'){
		uexWindow.toast("0","5","禁言用户成功…","2000");
	}else if(returnCode == '401'){
		uexWindow.toast("0","5","操作失败，用户名或密码错误…","2000");
	}else if(returnCode == '402'){
		uexWindow.toast("0","5","操作失败，无权操作管理组用户…","2000");
	}else if(returnCode == '403'){
		uexWindow.toast("0","5","操作失败，您没有该权限…","2000");
	}else{
		uexWindow.toast("0","5","操作失败，未知错误…","2000");
	}
}



/**
 * 处理帖子提升返回的结果
 * @param {json} data
 */
function showUpResult(data){
	uexWindow.closeToast();
	var returnCode = data.info;
	if(returnCode == '200'){
		uexWindow.toast("0","5","帖子提升成功…","2000");
	}else if(returnCode == '401'){
		uexWindow.toast("0","5","提升失败，用户名或密码错误…","2000");
	}else if(returnCode == '404'){
		uexWindow.toast("0","5","提升失败，帖子ID缺失…","2000");
	}else if(returnCode == '405'){
		uexWindow.toast("0","5","提升失败，只有楼主才可以提升…","2000");
	}else if(returnCode == '406'){
		uexWindow.toast("0","5","提升失败，该板块没有提升功能…","2000");
	}else if(returnCode == '407'){
		uexWindow.toast("0","5","提升失败，每次提升至少间隔10分钟…","2000");
	}else if(returnCode == '408'){
		uexWindow.toast("0","5","提升失败，您的YB余额不足…","2000");
	}else{
		uexWindow.toast("0","5","提升失败，未知错误…","2000");	
	}
}

/**
 * 添加到收藏
 */
function addToFavorite(){
	var tid = getLocalStorge('tid');
	var uid = getLocalStorge('uid');
	var password = getLocalStorge('pwd');
	if(!tid){
		uexWindow.alert('提示','缺少参数,请重新操作!','返回');
		return false;
	}
	
	if(!uid){
		uexWindow.alert('提示','您还未登陆，请先登录！','返回');
		return false;
	}
	
	uexWindow.toast("1","5","正在添加到收藏…","0");
	var requestURL = forumHost + '&ac=favorite&tid='+tid+'&uid='+uid+'&pwd='+password;
	xmlHttp(requestURL,showReturn);
}

/**
 * 添加帖子收藏的回调函数
 * @param {Object} data
 */
function showReturn(data){
	var returnCode = parseInt(data.info);
	if(returnCode > 1000){
		uexWindow.closeToast();
		uexWindow.toast("0","5","收藏成功…","2000");
	}else if(returnCode == 401){
		uexWindow.closeToast();
		uexWindow.toast("0","5","收藏失败，用户验证失败…","2000");
	}else if(returnCode == 404){
		uexWindow.closeToast();
		uexWindow.toast("0","5","收藏失败，未找到您要收藏的帖子…","2000");
	}else{
		uexWindow.closeToast();
		uexWindow.toast("0","5","收藏失败，未知错误…","2000");
	}
}

/**
 * 针对主题的操作
 */
function showAction(){
	var uid = getLocalStorge('uid');
	var authorid = getLocalStorge('authorid');
	var groupid = getLocalStorge('groupid');
	var fid = getLocalStorge('fid');
	
	if(!uid){
		var confirmButtom = new Array();
		confirmButtom[0] = '登录';
		confirmButtom[1] = '返回';
		confirmTag = 3;
		uexWindow.confirm('提示：','请登录后再进行操作！',confirmButtom);
		return false;
	}
	
	sheetTag = 2;
	if(authorid == uid){
		var upFids = ['3','316','627','626','625','624','623','622','304','305','635','634','633','325','632','631','630','309','598','604','89','641','642','643'];
		if(in_array(fid,upFids,false)){
			var menulist=new Array(2);
			menulist[0] = "回复";
			menulist[1] = "提升帖子";
			uexWindow.actionSheet("帖子操作","返 回",menulist);
		}else{
			var menulist=new Array(1);
			menulist[0] = "回复";
			uexWindow.actionSheet("帖子操作","返 回",menulist);
		}
		
	}else{
		if(in_array(groupid,['1','2','3','57','62','42'])){
			var menulist=new Array(3);
			menulist[0] = "回 复";
			menulist[1] = "收 藏";
			menulist[2] = "用户禁言";
			menulist[3] = "删除帖子";
			uexWindow.actionSheet("帖子操作","返 回",menulist);
		}else{
			var menulist=new Array(3);
			menulist[0] = "回 复";
			menulist[1] = "引 用";
			menulist[2] = "收 藏";
			uexWindow.actionSheet("帖子操作","返 回",menulist);
		}
	}
}

/**
 * 版主或管理员禁言用户的回调函数
 * @param {string} data 
 */
function BanUser(data){
	uexWindow.closeToast();
	var returnCode = data.info;
	if(returnCode == '200'){
		uexWindow.toast("0","5","禁言用户成功…","2000");
		var pid = getLocalStorge('rpid');
		$('.post[title="'+pid+'"] .post_content').html('<p style="background-color:#eee;font-size:0.8em;"> 提示：该用户已被删除或禁言，内容被屏蔽！</p>');
	}else if(returnCode == '401'){
		uexWindow.toast("0","5","操作失败，用户名或密码错误…","2000");
	}else if(returnCode == '402'){
		uexWindow.toast("0","5","操作失败，无权操作管理组用户…","2000");
	}else if(returnCode == '403'){
		uexWindow.toast("0","5","操作失败，您没有该权限…","2000");
	}else{
		uexWindow.toast("0","5","操作失败，未知错误…","2000");
	}
}

/**
 * 获取下一页帖子回复
 */
function getMorePost(){
	var isOver = $("#nextpage").hasClass("over");
	if(isOver){
		uexWindow.toast("0","5","已经显示完全部回复！","2000");
	}else{
		var tid = localStorage.getItem('tid');
		if(tid == ''){
			uexWindow.toast("0","5","数据获取失败！","3");
		}else{
			$('#nextpage').html('数据加载中……');
			postPage = postPage + 1;
			uexWindow.toast("1","5","数据加载中……","0");
			var url = forumHost + '&ac=post&tid='+tid+'&page='+postPage;
			xmlHttp(url,showMorePost);
		}
	}
}

/**
 * 显示下一页帖子回复
 * @param {Object} posts
 */
function showMorePost(posts){
	var postObj = $("#viewthread");
	var j = 1;
	var headThumb;
	var louceng;
	var preNum = (postPage-1) * 10;
	//显示posts
	for(var i in posts){
		j = j + 1;
		louceng = preNum + j;
		var reply = posts[i];
		headThumb = 'http://center.yeeyi.com/avatar.php?uid='+reply.authorid+'&size=small';
		var postDiv = '';
		var postDivHead = '<div ontouchstart="zy_touch(\'btn-newact\')" class="post" onclick="showReply('+reply.pid+');" title="'+reply.pid+'"><div class="post_header">';
		var postDivThumb = '<img src="'+headThumb+'" alt="">';
		var postAuthor = '<span class="post_author" title="'+reply.authorid+'"><span class="authorLeft">'+b64.decode(reply.author)+'</span><span class="louceng">'+louceng+'#</span></span>';
		var postDateline = '<div class="comment-meta"><span class="meta-sep">'+b64.decode(reply.dateline)+'</span></div></div>';
		h = 0;
		var postcommentObj = reply.comment;
		var postcomment = '<div class="viewthread_commontHead">点 评 </div>';
		for(h in postcommentObj){
			var pcomment = postcommentObj[h];
			postcomment = postcomment + '<div class="postcomment"><span style="font-weight: bold;">'+b64.decode(pcomment.author)+': </span><span>'+b64.decode(pcomment.comment)+'</span></div>';
			h = h + 1;
		}
		if(h == 0){
			postcomment = '';
		}
		var postContent = '<div class="post_content">'+b64.decode(reply.message)+postcomment+'</div>';
		var postFooter = '</div>';
		
		postDiv = postDivHead + postDivThumb + postAuthor + postDateline + postContent + postFooter;
		postObj.append(postDiv);
	}
	
	if(j == 11){
		$('#nextpage').html('查看下10条');
	}else{
		$('#nextpage').html('已全部显示').addClass('over');
	}
	uexWindow.closeToast();
}

/**
 * 回复中的高级模式跳转函数
 */
function replyByHighWay(){
	var uid = getLocalStorge('uid');
	if(!uid){
		var confirmButtom = new Array();
		confirmButtom[0] = '登录';
		confirmButtom[1] = '返回';
		confirmTag = 3;
		uexWindow.confirm('提示：','请登录后再回复！',confirmButtom);
		return false;
	}else{
		uexWindow.open('reply','0','reply.html','2','100%','100%','0');
	}
}

/**
 * 帖子回复
 */
function postNewReply(){
	var uid = getLocalStorge('uid');
	if(!uid){
		var confirmButtom = new Array();
		confirmButtom[0] = '登录';
		confirmButtom[1] = '返回';
		confirmTag = 3;
		uexWindow.confirm('提示：','请登录后再回复！',confirmButtom);
		return false;
	}
	
	uexWindow.toast("1","5","回复内容正在发布…","0");
	var allAid = '';
	

	var message = $.trim($('#message').val());
	var fid = getLocalStorge('fid');
	var username = getLocalStorge('username');
	var password = getLocalStorge('pwd');
	var tid = getLocalStorge('tid');
	
	
	if(message.length <= 2){
		uexWindow.closeToast();
		uexWindow.toast("0","5","提交失败，内容太短了些吧…","2000");
		return false;
	}
	
	if(!fid){
		uexWindow.closeToast();
		uexWindow.toast("0","5","提交失败，没有找到对应板块…","2000");
		return false;
	}
	
	if(!tid){
		uexWindow.closeToast();
		uexWindow.toast("0","5","提交失败，帖子ID信息丢失…","2000");
		return false;
	}
	
	if(!uid){
		uexWindow.closeToast();
		uexWindow.toast("0","5","提交失败，用户UID缺失…","2000");
		return false;
	}
	
	
	_message = encodeURIComponent(b64.encode(message));
	_region = '';
	_imgaid = '';
	_username = encodeURIComponent(b64.encode(username));
	_password = encodeURIComponent(password);
	
	var RequestUrl = forumHost + '&ac=reply&tid='+tid+'&message='+_message+'&fid='+fid+'&imgaid='+_imgaid+'&uid='+uid+'&username='+_username+'&password='+_password+'&region='+_region;
	
	xmlHttp(RequestUrl,replyCallBack);
}

/**
 * 删除回复的回调处理函数
 * @param {Object} data
 */
function showDelPostResult(data){
	uexWindow.closeToast();
	var returnCode = data.info;
	if(returnCode == '200'){
		uexWindow.toast("0","5","回复删除成功…","2000");
		var pid = getLocalStorge('rpid');
		$('.post[title="'+pid+'"]').remove();
	}else if(returnCode == '401'){
		uexWindow.toast("0","5","操作失败，用户名或密码错误…","2000");
	}else if(returnCode == '402'){
		uexWindow.toast("0","5","操作失败，无权操作管理组用户…","2000");
	}else if(returnCode == '403'){
		uexWindow.toast("0","5","操作失败，您没有该权限…","2000");
	}else if(returnCode == '404'){
		uexWindow.toast("0","5","操作失败，未找到对应回复…","2000");
	}else{
		uexWindow.toast("0","5","操作失败，未知错误…","2000");
	}
}

/**
 * 回复帖子中的回调处理函数
 * @param {Object} data
 */
function replyCallBack(data){
	uexWindow.closeToast();
	var returnInfo = data.info;
	if(parseInt(returnInfo) > 10000){
		uexWindow.toast("0","5","回复成功…","2000");
		appendNewReply(returnInfo);
	}else if(returnInfo == '403'){
		uexWindow.toast("0","5","发布失败，用户名或密码错误…","2000");
	}else if(returnInfo == '405'){
		uexWindow.toast("0","5","发布失败，您的用户组无权发帖…","2000");
	}else if(returnInfo == '406'){
		uexWindow.toast("0","5","发布失败，缺少参数…","2000");
	}else{
		uexWindow.toast("0","5","发布失败，请稍后重试…","2000");
	}
}

/**
 * 快速回复操作函数
 * @param {Object} pid
 */
function fastAppendReply(pid){
	var message = getLocalStorge('fastReply');
	var username = getLocalStorge('username');
	var authorid = getLocalStorge('uid');
	var dateline = '3秒前';
	var newReply = '';
	
	var postObj = $("#viewthread");
	var postDiv = '';
	var postDivHead = '<div ontouchstart="zy_touch(\'btn-newact\')" class="post" onclick="showReply('+pid+');" title="'+pid+'"><div class="post_header">';
	var postDivThumb = '<img src="css/images/avatar.gif" alt="">';
	var postAuthor = '<span class="post_author" title="'+authorid+'">'+username+'</span>';
	var postDateline = '<div class="comment-meta"><span class="meta-sep">'+dateline+'</span></div></div>';
	var postContent = '<div class="post_content">'+message+'</div>';
	var postFooter = '</div>';
		
	postDiv = postDivHead + postDivThumb + postAuthor + postDateline + postContent + postFooter;
	postObj.append(postDiv);
	var message = $.trim($('#message').val(''));
}

/**
 * 回复成功后追加回复内容到帖子尾部
 * @param {Object} pid
 */
function appendNewReply(pid){
	var message = $('#message').val();
	var username = getLocalStorge('username');
	var authorid = getLocalStorge('uid');
	var dateline = '3秒前';
	var newReply = '';
	
	var postObj = $("#viewthread");
	var postDiv = '';
	var postDivHead = '<div ontouchstart="zy_touch(\'btn-newact\')" class="post" onclick="showReply('+pid+');" title="'+pid+'"><div class="post_header">';
	var postDivThumb = '<img src="css/images/avatar.gif" alt="">';
	var postAuthor = '<span class="post_author" title="'+authorid+'">'+username+'</span>';
	var postDateline = '<div class="comment-meta"><span class="meta-sep">'+dateline+'</span></div></div>';
	var postContent = '<div class="post_content">'+message+'</div>';
	var postFooter = '</div>';
		
	postDiv = postDivHead + postDivThumb + postAuthor + postDateline + postContent + postFooter;
	postObj.append(postDiv);
	$('#message').val('');
}

/**
 * 追加回复内容
 * @param {Object} pid
 */
function appendNewSubReply(pid){
	
	var username = getLocalStorge('username');
	var message = getLocalStorge('replyMessage');
	
	var authorid = getLocalStorge('uid');
	var dateline = '5秒前';
	var postObj = $("#viewthread");
	
	var postDiv = '';
	var postDivHead = '<div ontouchstart="zy_touch(\'btn-newact\')" class="post" onclick="showReply('+pid+');" title="'+pid+'"><div class="post_header">';
	var postDivThumb = '<img src="css/images/avatar.gif" alt="">';
	var postAuthor = '<span class="post_author" title="'+authorid+'">'+username+'</span>';
	var postDateline = '<div class="comment-meta"><span class="meta-sep">'+dateline+'</span></div></div>';
	var postContent = '<div class="post_content">'+message+'</div>';
	var postFooter = '</div>';
		
	postDiv = postDivHead + postDivThumb + postAuthor + postDateline + postContent + postFooter;
	postObj.append(postDiv);
	
	localStorage.setItem('replyMessage','');
}

function goTo(type){
	if(type == 'home'){
		var uid = getLocalStorge('uid');
		if(!uid){
			uexWindow.alert("","请先登录再进入个人空间！","返回");
		}else{
			localStorage.setItem("contentType",'home');
			uexWindow.evaluateScript("root","0","showMainContent('home')");
			setTimeout(function(){
				uexWindow.open('root','0','index.html','2','100%','100%',0);
			},2000);
		}
	}else if(type == 'exit'){
		uexWidgetOne.exit();
	}else{
		localStorage.setItem("contentType",type);
		uexWindow.evaluateScript("root","0","showMainContent('"+type+"')");
		setTimeout(function(){
				uexWindow.open('root','0','index.html','2','100%','100%',0);
		},2000);
	}
}

/**
 * 字符是否存在于某个数组中，类似于PHP中的in_array()函数
 * @param {Object} needle
 * @param {Object} haystack
 * @param {Object} argStrict
 */
function in_array (needle, haystack, argStrict) {
    var key = '',strict = !! argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }

    return false;
}

/**
 * 关闭窗口
 */
function closeWindow(){
    var closeString = "uexWindow.close(-1);";
    uexWindow.evaluateScript('', '0', closeString);
}

/**
 * HTML5 localStorge.getItem 函数的封装
 * @param {Object} key
 */
function getLocalStorge(key){
	var item = localStorage.getItem(key);
	if(item=='' || item==null || typeof(item)=="undefined"){
		return false;
	}else{
		return item;
	}
}
